package org.hbhk.app.activity;

import org.hbhk.app.R;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class ShowBarcodeActivity extends Activity implements OnClickListener {

	private Button button;
	private TextView textView;
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.bar_1r);

		this.button = (Button) this.findViewById(R.id.Button01);
		this.button.setOnClickListener(this);
		this.textView = (TextView) this.findViewById(R.id.hello);

	}

	@Override
	public void onClick(View view) {
		Intent intent = new Intent("com.google.zxing.client.android.SCAN");
		intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
		this.startActivityForResult(intent, 0);
	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		// if (requestCode != 0) {
		// return;
		// }
		//
		// this.textView.setText(data.getStringExtra("SCAN_RESULT"));
		String contents = null;
		super.onActivityResult(requestCode, resultCode, data);
		if (requestCode == 0) {
		      if (resultCode == RESULT_OK) {
		         contents = data.getStringExtra("SCAN_RESULT");
		         String format = data.getStringExtra("SCAN_RESULT_FORMAT");
		         //moved here
		        // TextView tv = (TextView) findViewById(R.id.scanResult);
		         textView.setText(contents);
		         // Handle successful scan
		      } else if (resultCode == RESULT_CANCELED) {
		         // Handle cancel
		      }
		}
	}
}
